<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>资料导出</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css" />
    <link
      href="../../../bstable/css/bootstrap.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../bstable/css/bootstrap-table.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../css/bootstrap-select.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../css/bootstrap.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <style>
      input[name='btSelectAll'] {
        position: relative;
        bottom: 7px;
      }

      input[name='btSelectAll']::after {
        content: '全选';
        color: #000;
        position: relative;
        left: 15px;
        bottom: 3px;
      }

      .bootstrap-table {
        padding: 20px;
      }
    </style>
  </head>

  <body>
    <div class="tabe_div">
      <div
        class="search-wrap p_line text_ient"
        style="margin-bottom: -10px; border-bottom: 0"
      >
        <a class="find_a">职称等级：</a>
        <div
          id="select1"
          style="display: inline-block; padding-left: 1%; width: 150px"
        ></div>
        <a class="find_a">职称系列：</a>
        <div
          id="select2"
          style="display: inline-block; padding-left: 1%; width: 150px"
        ></div>
        <a class="find_a">专业：</a>
        <div
          id="select3"
          style="display: inline-block; padding-left: 1%; width: 150px"
        ></div>
        <a class="find_a">批次：</a>
        <div
          id="select4"
          style="display: inline-block; padding-left: 1%; width: 150px"
        ></div>
        <input type="button" value="查询" class="but_find" id="search" />
      </div>
      <p class="p_line text_ient" style="margin-bottom: -10px">
        <a class="find_a">学生姓名：</a>
        <input
          type="text"
          id="name"
          class="form_input text_ient"
          placeholder="输入学生姓名"
        />
        <a class="find_a">学生身份证号：</a>
        <input
          type="text"
          id="card"
          class="form_input text_ient"
          placeholder="输入身份证号"
          maxlength="18"
        />
        <a class="find_a">学生手机号：</a>
        <input
          type="text"
          id="phone"
          class="form_input text_ient"
          placeholder="输入手机号"
          maxlength="11"
        />
      </p>
      <table
        data-url="json/data_alae_list.json"
        id="table"
        class="table_style"
        style="margin: 20px auto"
      ></table>

      <div style="text-align: center; margin: 20px auto">
        <input type="button" value="导出资料" class="but_find" id="ziliao" />
        <input type="button" value="导出表格" class="but_find" id="biaoge" />
      </div>
    </div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/laydate-master/laydate.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="../../../js/bootstrap-select.min.js"></script>

    <script type="text/javascript">
      localStorage.setItem('name', '教务管理/资料导出(职称评审)');
      // 学历层次education，学校 school，专业train，批次batch
      $(function () {
        $('#search').on('click', function () {
          $('#table').bootstrapTable('refresh');
        });

        let select1 = initialSelect('#select1', []);
        let select2 = initialSelect('#select2', [], handleSeriesChange);
        let select3 = initialSelect('#select3', []);
        let select4 = initialSelect('#select4', []);

        $('#table').bootstrapTable({
          method: 'get',
          striped: true,
          singleSelect: false,
          url: baseUrl + 'studentInfo/getStudentList',
          dataType: 'json',
          pagination: true, //分页
          sidePagination: 'server',
          pageSize: 10,
          pageNumber: 1,
          search: false, //显示搜索框
          contentType: 'application/x-www-form-urlencoded',
          ajaxOptions: {
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
          },
          checkbox: true,
          queryParams: function (params) {
            params.trainType = 'title';
            params.professionalLevel = select1
              .getValue()
              .map((item) => item.name)
              .toString();
            params.professionalSeries = select2
              .getValue()
              .map((item) => item.name)
              .toString();
            params.majorName = select3
              .getValue()
              .map((item) => item.name)
              .toString();
            params.batch = select4
              .getValue()
              .map((item) => item.name)
              .toString();
            params.name = $('#name').val().trim();
            params.idNo = $('#card').val().trim();
            params.mobile = $('#phone').val().trim()
            params.userType = 'ziliao';
            params.offset = params.offset / params.limit;
            return params;
          },
          responseHandler: function (res) {
            var list = res.data.result.records;
            var maps = {
              education: '学历提升',
              occupation: '职业技能',
              title: '职称评审',
              train: '执业资格',
            };
            var commits = [
              '已保存',
              '已提交',
              '财务驳回',
              '教务驳回',
              '待财务审核',
              '待教务审核',
              '教务确认',
            ];
            list.forEach(function (item, i) {
              item.trainType = maps[item.trainType];
              item.commitFlag = commits[item.commitFlag];
              !item && (list[i] = {});
              item.feeFlag = item.feeFlag == 1 ? '已缴费' : '未缴费';
            });
            return {
              rows: list,
              total: res.data.total,
            };
          },
          columns: [
            {
              checkbox: true,
              width: 80,
            },
            {
              field: 'no',
              title: '序号',
              sortable: true,
              align: 'center',
              formatter: function (value, row, index) {
                var pageSize =
                  $('#table').bootstrapTable('getOptions').pageSize;
                var pageNumber =
                  $('#table').bootstrapTable('getOptions').pageNumber;
                return pageSize * (pageNumber - 1) + index + 1;
              },
            },
            {
              title: '学生姓名',
              field: 'name',
              align: 'center',
              valign: 'middle',
            },
            {
              title: '身份证号',
              field: 'idNo',
              align: 'center',
            },
            {
              title: '老师手机号',
              field: 'teacherMobile',
              align: 'center',
            },
            {
              title: '老师姓名',
              field: 'teacherName',
              align: 'center',
            },
            {
              title: '报考类型',
              field: 'trainType',
              align: 'center',
            },
            {
              title: '提交日期',
              field: 'term',
              align: 'center',
            },
            // {
            //     title: '课程开始时间',
            //     field: 'classStartDate',
            //     align: 'center'
            // },
            // {
            //     title: '课程结束时间',
            //     field: 'classEndDate',
            //     align: 'center'
            // },
            {
              title: '审核状态',
              field: 'commitStr',
              align: 'center',
            },
          ],
        });
        $('#ziliao').on('click', function () {
          var rows = $('#table').bootstrapTable('getSelections');
          var studentId = [];
          if (!rows.length) {
            return alert('请至少选择一项');
          }

          rows.forEach(function (item) {
            studentId.push(item.name + '_' + item.idNo);
          });
          
          window.open(
            baseUrl +
              'studentInfo/dataExport' +
              '?studentId=' +
              studentId.join(',')
          );
          return false;
        });

        function transformRequest(obj) {
          //console.log('obj',obj)
          var str = [];
          for (var p in obj) {
            str.push(encodeURIComponent(p) + '=' + encodeURIComponent(obj[p]));
          }
          //console.log(str.join("&"))
          return str.join('&');
        }

        $('#biaoge').on('click', function () {
          var rows = $('#table').bootstrapTable('getSelections');
          var studentId = [];
          if (!rows.length) {
            return alert('请至少选择一项');
          }
          rows.forEach(function (item) {
            studentId.push(item.id);
          });
          
          window.open(
            baseUrl +
              'studentInfo/sheetExport' +
              '?studentIds=' +
              studentId.join(',') +
              '&exportType=jobTitle'
          );
        });

        function querySchool(data) {
          $.ajax({
            url: baseUrl + 'education/querySchoolList',
            method: 'Post',
            data:
              'educationId=' + data.arr.map((item) => item.value).toString(),
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            success: function (data) {
              const list = data.map((item) => ({
                value: item.id,
                name: item.schoolName,
              }));
              myschool.update({ data: list });
            },
          });
        }

        function queryCourse(data) {
          $.ajax({
            url: baseUrl + 'education/queryCourseList',
            method: 'Post',
            data: 'schoolId=' + data.arr.map((item) => item.value).toString(),
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            success: function (data) {
              const list = data.map((item) => ({
                value: item.id,
                name: item.courseName,
              }));
              mycourse.update({ data: list });
            },
          });
        }
        getList();
        function getList() {
          $.ajax({
            url: baseUrl + 'education/queryTitleList',
            async: false,
            method: 'Post',
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            success: (data) => {
              const list = data.map((item) => ({
                value: item.id,
                name: item.titleName,
              }));
              select1.update({ data: list });
            },
          });

          $.ajax({
            url: baseUrl + 'education/queryBatchList',
            method: 'Post',
            data: {
              trainType: 'title',
            },
            success: (data) => {
              const list = data.map((item) => ({
                value: item.id,
                name: item.batch,
              }));
              select4.update({ data: list });
            },
          });

          $.ajax({
            url: baseUrl + 'education/queryProfessionalSeriesList',
            async: false,
            method: 'Post',
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            success: (data) => {
              const list = data.map((item) => ({
                value: item.id,
                name: item.professionalSeries,
              }));
              select2.update({ data: list });
            },
          });
        }

        function handleSeriesChange(data) {
          $.ajax({
            url: baseUrl + 'education/queryOccupationInfoList',
            method: 'Post',
            data:
              'occupationId=' + data.arr.map((item) => item.value).toString(),
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            success: (data) => {
              const list = data.map((item) => ({
                value: item.id,
                name: item.occupationInfoName,
              }));
              select3.update({ data: list });
            },
          });
        }
      });
    </script>
  </body>
</html>
